Don't use `-C metadata` cdylibs like we do with dylibs
authorAlex Crichton <alex@alexcrichton.com>
Mon, 24 Apr 2017 20:41:27 +0000 (13:41 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 2 May 2017 15:52:07 +0000 (08:52 -0700)
Dylibs don't get any metadata/extra filename info applied to them as "final
targets" because it can mess with system-specific information (e.g. on OSX) so
this just applies the same logic to cdylibs which need similar treatment on more
platforms (like Windows).

Closes #3934

src/cargo/core/manifest.rs
src/cargo/ops/cargo_rustc/context.rs
tests/build.rs

index ae7915027528fe380f06772b19765b286dfa95f9..600aa1e11927da983ab9c3755cdf857dc08cdbcd 100644 (file)
@@ -435,6 +435,19 @@ impl Target {
         }
     }
 
+    pub fn is_cdylib(&self) -> bool {
+        let libs = match self.kind {
+            TargetKind::Lib(ref libs) => libs,
+            _ => return false
+        };
+        libs.iter().any(|l| {
+            match *l {
+                LibKind::Other(ref s) => s == "cdylib",
+                _ => false,
+            }
+        })
+    }
+
     pub fn linkable(&self) -> bool {
         match self.kind {
             TargetKind::Lib(ref kinds) => {
index 46904749f2598ded992583c5b3274b0f5cc360cb..27cd369ba6df1f9a83b993e98bebdbcf82f42281 100644 (file)
@@ -388,7 +388,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         // just here for rustbuild. We need a more principled method
         // doing this eventually.
         if !unit.profile.test &&
-            unit.target.is_dylib() &&
+            (unit.target.is_dylib() || unit.target.is_cdylib()) &&
             unit.pkg.package_id().source_id().is_path() &&
             !env::var("__CARGO_DEFAULT_LIB_METADATA").is_ok() {
             return None;
@@ -940,7 +940,7 @@ fn env_args(config: &Config,
     let mut rustflags = Vec::new();
 
     let name = name.chars().flat_map(|c| c.to_lowercase()).collect::<String>();
-    // Then the target.*.rustflags value... 
+    // Then the target.*.rustflags value...
     let target = build_config.requested_target.as_ref().unwrap_or(&build_config.host_triple);
     let key = format!("target.{}.{}", target, name);
     if let Some(args) = config.get_list_or_split_string(&key)? {
index 56f5c7f9fc1214ca4fb0c614a4eb035800fef873..3f0b247871fc18b2dfda5288bf1aba50a1af3bbd 100644 (file)
@@ -2909,3 +2909,34 @@ fn rustc_wrapper() {
                     "[RUNNING] `/usr/bin/env rustc --crate-name foo [..]")
                 .with_status(0));
 }
+
+#[test]
+fn cdylib_not_lifted() {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            authors = []
+            version = "0.1.0"
+
+            [lib]
+            crate-type = ["cdylib"]
+        "#)
+        .file("src/lib.rs", "");
+
+    assert_that(p.cargo_process("build"), execs().with_status(0));
+
+    let files = if cfg!(windows) {
+        vec!["foo.dll.lib", "foo.dll.exp", "foo.dll"]
+    } else if cfg!(target_os = "macos") {
+        vec!["libfoo.dylib"]
+    } else {
+        vec!["libfoo.so"]
+    };
+
+    for file in files {
+        println!("checking: {}", file);
+        assert_that(&p.root().join("target/debug/deps").join(&file),
+                    existing_file());
+    }
+}